package com.lz.demo3;

import java.util.Random;

/**
 * @ClassName AK47
 * @Description 武器类（AK47武器相关的属性数据、运算代码）
 * @Author 2214361854
 * @Date 2022/5/28 14:28
 * @Version 1.0
 */
public class AK47 {
    int bullets = 100;

    public void fire() {
        if (bullets == 0) {
            System.out.println("没有子弹");
            return;
        }
        //随机产生发射子弹数量
        int r = new Random().nextInt(10);
        //要发射的数量，比现有子弹多
        if (r > bullets) {
            r = bullets;//有多少发多少
        }
        bullets -= r;
        for (int i = 0; i < r; i++) {
            System.out.print("突");
        }
        System.out.println("~");
        if (bullets == 0) {
            System.out.println("弹夹空了");
        }
    }

    public void load() {
        bullets = 100;
        System.out.println("弹夹已装满");
    }
}
